Modul:Postava
local infoboxCharacter = {} --high level - infoboxes group function infoboxCharacter.blockCreate(frame) local args = frame.args --functions --dividing up the line into the massive of the underlines by a determined symbol function split(str, separator, reg) local result = {} --Testing of the example if (not reg) then regExp = true else regExp = false end --variable of positions local n local k --managing variables local s = 0 local i = 1 --line polishing while k ~= str:len() do --separator searching local substring n, k = str:find(separator, s + 1, regExp) --if searching didn't bring any result if (k nil or n nil) then resulti = str:sub(s + 1, str:len()) break end --if the separator is found substring = str:sub(s + 1, n - 1) --result adding if substring ~= '' then resulti = substring i = i + 1 end s = k end return result end --testing of the parameters function paramCheck(param) if param and param ~= '' then return true else return false end end --infobox creating function infoboxCreate(prefix) --arguments polishing local data = {} --name if paramCheck(argsprefix..'jmeno') then data.name = argsprefix..'jmeno' elseif prefix ~= '' then data.name = prefix:sub(1, prefix:len() - 1) else data.name = tostring(mw.title.getCurrentTitle()) end --title if paramCheck(argsprefix..'titul') then data.title = argsprefix..'titul' end --age if paramCheck(argsprefix..'věk') then data.age = mw.ustring.lower(argsprefix..'věk') end --type if paramCheck(argsprefix..'druh') then data.kind = mw.ustring.lower(argsprefix..'druh') end --sex if paramCheck(argsprefix..'pohlaví') then data.gender = mw.ustring.lower(argsprefix..'pohlaví') end --different information data.differentInfo = {} --occupation if paramCheck(argsprefix..'zaměstnání') then data.differentInfo+ 1 = {'Zaměstnání', argsprefix..'zaměstnání'} end --living place if paramCheck(argsbydlení') then data.differentInfo+ 1 = {'Místo bydlení', argsbydlení'} end --other local dIC = 1 while paramCheck(argsinformace '..dIC) do local dInfo = split(argsinformace '..dIC, ':') if dInfo2 then data.differentInfo+ 1 = {dInfo1, dInfo2} end dIC = dIC + 1 end --sounding data.voiceInfo = {} --czech if paramCheck(argsozvučování') then data.voiceInfo+ 1 = {'České', argsozvučování'} end --english if paramCheck(argsozvučování') then data.voiceInfo+ 1 = {'Originální', argsozvučování'} end --Czech singing if paramCheck(argsozvučování písní') then data.voiceInfo+ 1 = {'České písní', argsozvučování písní'} end --English singing if paramCheck(argsozvučování písní') then data.voiceInfo+ 1 = {'Originální písní', argsozvučování písní'} end --other local vIC = 1 while paramCheck(argsозвучка '..vIC) do local vInfo = split(argsозвучка '..vIC, ':') if vInfo2 then data.voiceInfo+ 1 = {vInfo1, vInfo2} end vIC = vIC + 1 end --relatives data.relativesInfo = {} local rIC = 1 while paramCheck(args'..rIC) do local rInfo = split(args'..rIC, ':') if rInfo2 then data.relativesInfo+ 1 = {rInfo1, rInfo2} end rIC = rIC + 1 end --character colours data.colorTable = {} if paramCheck(argsprefix..'barva') then local colors = split(argsprefix..'barva', '/') data.colorTable+ 1 = {'Barva', colors} --preliminary determination of the colour scheme - background data.bgColor = colors1 end if paramCheck(argshřívy') then local colors = split(argshřívy', '/') data.colorTable+ 1 = {'Hříva', colors} --preliminary determination of the colour scheme - text data.fontColor = colors1 end if paramCheck(argsočí') then local colors = split(argsočí', '/') data.colorTable+ 1 = {'Oči', colors} end local ctc = 1 while argsbarva '..ctc do local color = split(argsbarva '..ctc, ':') if color2 then local parsedColor = split(color2, '/') data.colorTable+ 1 = {color1, parsedColor} end ctc = ctc + 1 end --cutie marks data.cutieMarks = {} local cMC = 1 while paramCheck(argsznačky '..cMC) or paramCheck(argsznačky '..cMC) do data.cutieMarkscMC = {} --background colour if paramCheck(argspozadí značky '..cMC) then data.cutieMarkscMC.cmBackground = argspozadí značky '..cMC elseif data.bgColor then data.cutieMarkscMC.cmBackground = data.bgColor else data.cutieMarkscMC.cmBackground = 'inherit' end --size if paramCheck(argsznačky '..cMC) then data.cutieMarkscMC.cmSize = argsznačky '..cMC else data.cutieMarkscMC.cmSize = '38x38px' end --image if paramCheck(argsznačky '..cMC) then data.cutieMarkscMC.cmImage = argsznačky '..cMC end --description if paramCheck(argsznačky '..cMC) then data.cutieMarkscMC.cmDescription = argsznačky '..cMC end cMC = cMC + 1 end --colour theme --background colour if paramCheck(argspozadí titulu') then data.bgColor = argspozadí titulu' elseif not data.bgColor then data.bgColor = 'inherit' end --text colour if paramCheck(argstextu titulu') then data.fontColor = argstextu titulu' elseif not data.fontColor then data.fontColor = 'transparent' end --contents cover local infoboxOuter = mw.html.create('div') --infobox basis local infobox = mw.html.create('div') infoboxOuter:addClass('ib1_infoboxCharacter') --functions ---------------------------------------------------------- --images and buttons creation (out of date) function imageCreateOld(name, dNone) local image = mw.html.create('div') image:addClass('infBlock') if not argsprefix..'titul' or argsprefix..'titul' '' then image:css('margin', '6px 0 0 0') end if dNone then image:css('display', 'none') end image:wikitext('[[Soubor:'..argsname..'|250px|link=]]') return image end function buttonCreateOld(name) local button = mw.html.create('div') button:addClass('infButton') button:css('color', data.fontColor) button:css('background', data.bgColor) button:wikitext(argsname) return button end ------------------------------------------------------------- --creations of sections with the information about the sex and the age function kindGenderCreate(text, image) local label = mw.html.create('div') if image then local imgBlock = mw.html.create('div') imgBlock:wikitext('link=') label:css('padding-left', '23px') label:node(imgBlock) else label:css('padding-left', '3px') end label:wikitext(text) return label end --table line creation function lineCreate(title, text) local line = mw.html.create('tr') local leftColumn = mw.html.create('th') leftColumn:wikitext(title) line:node(leftColumn) local rightColumn = mw.html.create('td') rightColumn:wikitext(text) line:node(rightColumn) return line end --creation of the empty rolling table with the title function collapsibleTableCreate(label) local colTable = mw.html.create('table') colTable:addClass('mw-collapsible mw-collapsed') local headerLine = mw.html.create('tr') local header = mw.html.create('th') header:css('background-color', data.bgColor) header:css('color', data.fontColor) header:wikitext(label) header:attr('colspan', '6') headerLine:node(header) colTable:node(headerLine) return colTable end --colourbox creation function colorBoxCreate(colors, borderColor) local colorBox = mw.html.create('div') colorBox:addClass('infoboxCharacter_colorBox') if (borderColor) then colorBox:css('border', '2px solid '..borderColor) else colorBox:css('border', '1px solid gray') end width = 100 / #colors for i = 1, #colors do local innerElement = mw.html.create('div') innerElement:css('background-color', colorsi) innerElement:css('width', width..'%') innerElement:attr('title', colorsi) colorBox:node(innerElement) end return colorBox end --contents --title local header = mw.html.create('div') header:addClass('infoboxCharacter_header') header:css('background-color', data.bgColor) local headerText = mw.html.create('div') headerText:wikitext(data.name ) headerText:css('color', data.fontColor) header:node(headerText) --титул local title if data.title then title = mw.html.create('div') title:addClass('infoboxCharacter_title') title:wikitext(data.title) end ------------------------------ --images and buttons (out of date) local imgOld1, imgOld2, imgOld3, imgOld4 if paramCheck(argsprefix..'obraz') then imgOld1 = imageCreateOld(prefix..'obraz1') end if paramCheck(argsprefix..'obraz2') then imgOld2 = imageCreateOld(prefix..'obraz2', true) end if paramCheck(argsprefix..'obraz3') then imgOld3 = imageCreateOld(prefix..'obraz3', true) end if paramCheck(argsprefix..'obraz4') then imgOld4 = imageCreateOld(prefix..'obraz4', true) end local butOld if paramCheck(argsprefix..'obraz2') then butOld = mw.html.create('div') butOld:cssText('width:100%; margin:6px 0 6px; text-align:center') butOld:node(buttonCreateOld(prefix..'podpis1')) butOld:node(buttonCreateOld(prefix..'podpis2')) if paramCheck(argsprefix..'obraz3') then butOld:node(buttonCreateOld(prefix..'podpis3')) end if paramCheck(argsprefix..'obraz4') then butOld:node(buttonCreateOld(prefix..'podpis4')) end end --------------------------- --type and sex local kindGender if data.kind or data.gender then kindGender = mw.html.create('div') kindGender:addClass('infoboxCharacter_kindGender colorlink') local customKind --type if data.kind then local kind = mw.html.create('div') local textKind local kindImg if data.kind 'jednorožec' then textKind = 'Jednorožecг' kindImg = 'Unicorn picto' elseif data.kind 'pegas' then textKind = 'Pegas' kindImg = 'Pegasus picto' elseif data.kind 'zemní pony' or data.kind 'zemní poník' then textKind = 'Zemní pony' end kindImg = 'Earthpony picto' elseif data.kind 'alicorn' then textKind = 'Alicorn' kindImg = 'Alicorn picto' else textKind = data.kind customKind = true end local kind = kindGenderCreate(textKind, kindImg) kindGender:node(kind) end --sex if data.gender and data.gender 'muž' or data.gender 'žen' then local gender = mw.html.create("div") local genderText local genderImg if data.gender 'muž' or data.gender 'mužsky' then if customKind then genderText = 'Muž.' elseif data.age 'dět' then genderText = 'Hříbě' else genderText = 'Hřebec' end genderImg = 'Male picto' else if customKind then genderText = 'Žen.' elseif data.age 'dět' then genderText = 'Kobylka' else genderText = 'Kobyla' end genderImg = 'Female picto' end local gender = kindGenderCreate(genderText, genderImg) kindGender:node(gender) end end --different information local diffInfoTable if #data.differentInfo ~= 0 then diffInfoTable = mw.html.create('table') diffInfoTable:addClass('infoboxCharacter_infoTable') for i = 1, #data.differentInfo do local line = lineCreate(data.differentInfoi1, data.differentInfoi2) diffInfoTable:node(line) end end --sounding local voiceTable if #data.voiceInfo ~= 0 then voiceTable = collapsibleTableCreate('Ozvučování') voiceTable:addClass('infoboxCharacter_collapsibleInfoTable') for i = 1, #data.voiceInfo do local line = lineCreate(data.voiceInfoi1, data.voiceInfoi2) voiceTable:node(line) end end --relatives local relativesTable if #data.relativesInfo ~= 0 then relativesTable = collapsibleTableCreate('Příbuzní') relativesTable:addClass('infoboxCharacter_collapsibleInfoTable') for i = 1, #data.relativesInfo do local line = lineCreate(data.relativesInfoi1, data.relativesInfoi2) relativesTable:node(line) end end --appearance local appearanceTable if data.colorTable1 or data.cmImage or data.cmDescription then appearanceTable = collapsibleTableCreate('Vzhled') appearanceTable:addClass('infoboxCharacter_appearanceTable') --colours if data.colorTable1 then local length = #data.colorTable local colspan local tr for i = 1, length do if length - i 1 and length % 3 2 then colspan = '3' elseif length - i 0 and length % 3 1 then colspan = '6' else colspan = '2' end if i % 3 1 then tr = mw.html.create('tr') end local th = mw.html.create('th') th:attr('colspan', colspan) th:wikitext(data.colorTablei1..' ') local colorBox = colorBoxCreate(data.colorTablei2) th:node(colorBox) tr:node(th) if (i % 3 0 or length - i 0) then appearanceTable:node(tr) end end end --cutie mark if #data.cutieMarks > 0 then local tr = mw.html.create('tr') local td = mw.html.create('td') td:attr("colspan", "6") local label = mw.html.create('span') label:wikitext('Značka') --button local rButton if #data.cutieMarks > 1 then --left local lButton = mw.html.create('div') lButton:addClass('ib1_appearance_lButton ib1_cmButton') lButton:css('background-color', data.bgColor) lButton:attr('title', 'Předchozí značka') local lArrow = mw.html.create('div') lArrow:css('border-right-color', data.fontColor) lButton:node(lArrow) --addition of the left td:node(lButton) --right rButton = mw.html.create('div') rButton:addClass('ib1_appearance_rButton ib1_cmButton') rButton:css('background-color', data.bgColor) rButton:attr('title', 'Příští značka') local rArrow = mw.html.create('div') rArrow:css('border-left-color', data.fontColor) rButton:node(rArrow) end --description and picture for i = 1, #data.cutieMarks do --description local description if data.cutieMarksi.cmDescription then description = mw.html.create('div') description:node(label) description:wikitext(' '..data.cutieMarksi.cmDescription) end --image local image if data.cutieMarksi.cmImage then image = mw.html.create('div') image:wikitext('[[soubor:'..data.cutieMarksi.cmImage..'|'..data.cutieMarksi.cmSize..'|link=]]') image:css("background-color", data.cutieMarksi.cmBackground) end --cover local wrapper if description and image then wrapper = mw.html.create('div') wrapper:addClass('ib1_appearance_cmComplete ib1_cm') wrapper:node(description) wrapper:node(image) elseif description then wrapper = description wrapper:addClass('ib1_appearance_cmDescription ib1_cm') else wrapper = mw.html.create('div') wrapper:node(label) wrapper:node(image) wrapper:addClass('ib1_appearance_cmImage ib1_cm') end --hiding the unwanted marks if i > 1 then wrapper:css('display', 'none') end --addition td:node(wrapper) end --addition of the right button if rButton then td:node(rButton) end tr:node(td) appearanceTable:node(tr) end end --gallery local gallery if paramCheck(argsprefix..'Galerie') then gallery = mw.html.create('div') gallery:addClass('infoboxCharacter_gallery colorlink') gallery:css('color', data.fontColor) gallery:css('background-color', data.bgColor) gallery:wikitext('[['..argsprefix..'galerie'..'|Galerie]]') end end return infoboxCharacter